package com.yan;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.concurrent.TimeoutException;


/*
    消息生产者
 */
public class Producer {


    public static void main(String[] args) throws Exception, TimeoutException {
        //获取连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUri("amqp://root:root@1.116.195.238:5672/%2f");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        // 声明fanout类型的交换器
        channel.queueDeclare(QueueConstants.defaultQueueName, false, false, false, null);
        channel.basicPublish(QueueConstants.empty,
                QueueConstants.defaultQueueName,  //
                null,
                ("hello world fan:").getBytes("utf-8"));


        channel.close();
        connection.close();

    }

}
